package com.water.camera.mark;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.water.camera.bean.EditItem;
import com.water.camera.databinding.LayoutWatermark62Binding;

import java.text.SimpleDateFormat;
import java.util.ArrayList;

public class Mark62 extends BaseMark {

    LayoutWatermark62Binding binding;

    public Mark62(@NonNull Context context) {
        super(context);
    }

    public Mark62(@NonNull Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public Mark62(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    protected void init(int type) {
        if (type == 0) {
            binding = LayoutWatermark62Binding.inflate(LayoutInflater.from(getContext()));
            addView(binding.getRoot());
            hideView(binding.bottom);
            for (int i = 3; i < binding.mid.getChildCount(); i++) {
                binding.mid.getChildAt(i).setVisibility(View.GONE);
            }
        } else {
            binding = LayoutWatermark62Binding.inflate(LayoutInflater.from(getContext()), this, true);
        }
        update();
    }

    @Override
    public void update() {
        setText(binding.binding1, "title62", binding.binding1);
        setText(binding.binding3, "time62", binding.binding2);
        setTime(binding.binding3, new SimpleDateFormat("yyyy-MM-dd"));
        setWeek(binding.binding4);
        setTime(binding.binding5, new SimpleDateFormat("HH:mm"));
        setText(binding.binding7, "area62", binding.binding6);
        setText(binding.binding9, "content62", binding.binding8);
        setText(binding.binding11, "worker62", binding.binding10);
        setText(binding.binding13, "charge62", binding.binding12);

        setText(binding.binding15, "weather62", binding.binding14);
        setText(binding.binding17, "didian62", "在这里", binding.binding16);
        setText(binding.binding19, "height62", binding.binding18);
        setText(binding.binding21, "angle62", binding.binding20);
        setText(binding.binding23, "jingwei62", binding.binding22);
        String s = new EditItem("jingwei62").getStringPoint();
        binding.binding23.setText(s);

        setText(binding.binding25, "beizhu62", binding.binding24);

        setText(binding.binding27, "build62", binding.binding26);
        setText(binding.binding29, "jianli62", binding.binding28);
        setText(binding.binding31, "shigong62", binding.binding30);
        setText(binding.binding33, "sheji62", binding.binding32);
        setText(binding.binding35, "kancha62", binding.binding34);

        super.update();
    }

    @Override
    public ArrayList<EditItem> getEditItems() {
        ArrayList<EditItem> list = new ArrayList<>();
        list.add(new EditItem("title62", "标题"));
        list.add(new EditItem("time62", "时间", true));

        list.add(new EditItem("area62", "施工区域"));
        list.add(new EditItem("content62", "施工内容"));
        list.add(new EditItem("worker62", "施工责任人"));
        list.add(new EditItem("charge62", "监理责任人"));

        list.add(new EditItem("weather62", "天气"));

        list.add(new EditItem("didian62", "地点"));
        list.add(new EditItem("height62", "海拔"));
        list.add(new EditItem("angle62", "方位角"));

        list.add(new EditItem("jingwei62", "经纬度"));

        list.add(new EditItem("result62", "备注"));

        list.add(new EditItem("build62", "建设单位"));
        list.add(new EditItem("jianli62", "监理单位"));
        list.add(new EditItem("shigong62", "施工单位"));
        list.add(new EditItem("sheji62", "设计单位"));
        list.add(new EditItem("kancha62", "勘察单位"));

        return list;
    }

    @Override
    public void onValueChange(EditItem item) {
        if (item.isTime) {
            setTime(binding.binding3, new SimpleDateFormat("yyyy-MM-dd"));
            setWeek(binding.binding4);
            setTime(binding.binding5, new SimpleDateFormat("HH:mm"));
        } else {
            super.onValueChange(item);
        }
    }
}
